package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;
import gt.edu.usac.model.vo.idiomaNivelViewImpl;
import gt.edu.usac.model.vo.idiomaProfesorViewImpl;
import gt.edu.usac.model.vo.idiomaViewImpl;
import gt.edu.usac.model.vo.personaParamsViewImpl;
import gt.edu.usac.model.vo.profesorImpViewImpl;
import gt.edu.usac.model.vo.profesorParamViewImpl;

import gt.edu.usac.viewcontroller.utils.JSFUtils;

import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;


import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.data.CoreColumn;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.component.core.data.CoreTableSelectOne;
import oracle.adf.view.faces.component.core.input.CoreInputText;
import oracle.adf.view.faces.component.core.input.CoreSelectInputDate;
import oracle.adf.view.faces.component.core.input.CoreSelectItem;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelGroup;
import oracle.adf.view.faces.component.core.layout.CorePanelHeader;
import oracle.adf.view.faces.component.core.layout.CorePanelHorizontal;
import oracle.adf.view.faces.component.core.layout.CorePanelTip;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;

import oracle.adf.view.faces.component.core.output.CoreOutputText;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;
import oracle.jbo.domain.DBSequence;

public class AgregarProfesor {
    private HtmlForm form1;
    private BindingContainer bindings;
    private CorePanelGroup panelGroup2;
    private CorePanelHorizontal panelHorizontal1;
    private CoreTable table1;
    private CoreColumn column1;
    private CoreOutputText outputText2;
    private CoreTableSelectOne tableSelectOne1;
    private CoreTable table2;
    private CoreTableSelectOne tableSelectOne2;
    private CoreColumn column2;
    private CoreOutputText outputText3;
    private CorePanelGroup panelGroup3;
    private CorePanelForm panelForm1;
    private CoreInputText inputText1;
    private CoreInputText inputText3;
    private CoreInputText inputText4;
    private CoreSelectOneChoice inputText5;
    private CoreSelectItem selectItem1;
    private CoreSelectItem selectItem2;
    private CoreInputText inputText6;
    private CoreInputText inputText7;
    private CoreInputText inputText8;
    private CoreSelectInputDate selectInputDate1;
    private CoreInputText inputText10;
    private CoreInputText inputText12;
    private CoreInputText inputText13;
    private CoreInputText inputText14;
    private CoreInputText inputText15;
    private CoreSelectOneChoice inputText16;
    private CoreSelectItem selectItem5;
    private CoreSelectItem selectItem3;
    private CoreSelectItem selectItem4;
    private CoreSelectItem selectItem6;
    private CoreCommandButton commandButton5;
    private CoreCommandButton commandButton6;
    private CorePanelHeader panelHeader1;
    private CorePanelHeader panelHeader2;
    private CorePanelGroup panelGroup4;
    private CoreCommandButton commandButton3;
    private CoreCommandButton commandButton2;
    private CoreCommandButton commandButton4;
    private CorePanelHorizontal panelHorizontal2;
    private CoreCommandButton commandButton1;
    private CoreCommandButton commandButton7;
    private CoreSelectOneChoice selectOneChoice1;
    private UISelectItems selectItems1;
    private CorePanelTip panelTip1;
    private CoreOutputText outputText1;
    private CoreOutputText outputText503;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }


    public BindingContainer getBindings() {
        return this.bindings;
    }

    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }

    public String commandButton1_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("agregarProfesor");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty() ) {
            return null;
        }
        if(result!=null && (Integer)result>0){
            JSFUtils.setExpressionValue("#{bindings.idProfe.inputValue}", (Integer)result);
            JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}", 1);
            AppModuleImpl service = getAppModule();
            idiomaProfesorViewImpl profe = service.getidiomaProfesorView1();
            profe.executeQuery();
            outputText503.setValue("");
        }
        else{
            outputText503.setValue("Hubo un error al agregar el profesor, verifique que los campos sean correctos.");
        }
        
      /*  System.out.println(result);
        System.out.println(JSFUtils.resolveExpression("#{bindings.idProfe.inputValue}"));*/
        return null;
    }

    public AppModuleImpl getAppModule() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        DCDataControl dc = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }


    public void setPanelGroup2(CorePanelGroup panelGroup2) {
        this.panelGroup2 = panelGroup2;
    }

    public CorePanelGroup getPanelGroup2() {
        return panelGroup2;
    }


    public void setPanelHorizontal1(CorePanelHorizontal panelHorizontal1) {
        this.panelHorizontal1 = panelHorizontal1;
    }

    public CorePanelHorizontal getPanelHorizontal1() {
        return panelHorizontal1;
    }

    public void setTable1(CoreTable table1) {
        this.table1 = table1;
    }

    public CoreTable getTable1() {
        return table1;
    }

    public void setColumn1(CoreColumn column1) {
        this.column1 = column1;
    }

    public CoreColumn getColumn1() {
        return column1;
    }

    public void setOutputText2(CoreOutputText outputText2) {
        this.outputText2 = outputText2;
    }

    public CoreOutputText getOutputText2() {
        return outputText2;
    }

    public void setTableSelectOne1(CoreTableSelectOne tableSelectOne1) {
        this.tableSelectOne1 = tableSelectOne1;
    }

    public CoreTableSelectOne getTableSelectOne1() {
        return tableSelectOne1;
    }


    public void setTable2(CoreTable table2) {
        this.table2 = table2;
    }

    public CoreTable getTable2() {
        return table2;
    }


    public void setTableSelectOne2(CoreTableSelectOne tableSelectOne2) {
        this.tableSelectOne2 = tableSelectOne2;
    }

    public CoreTableSelectOne getTableSelectOne2() {
        return tableSelectOne2;
    }


    public void setColumn2(CoreColumn column2) {
        this.column2 = column2;
    }

    public CoreColumn getColumn2() {
        return column2;
    }

    public void setOutputText3(CoreOutputText outputText3) {
        this.outputText3 = outputText3;
    }

    public CoreOutputText getOutputText3() {
        return outputText3;
    }

    public String commandButton3_action() {
        if ((Integer)JSFUtils.resolveExpression("#{bindings.idProfe.inputValue}") != -1) {
            AppModuleImpl service = getAppModule();
            idiomaProfesorViewImpl profe = service.getidiomaProfesorView1();
            idiomaViewImpl  idioma = service.getidiomaView1();
            RowSetIterator iterador=profe.createRowSetIterator("iter");
            iterador.reset();            
            while(iterador.hasNext()){
            Row row=iterador.next();            
            if(  new DBSequence((oracle.jbo.domain.Number)row.getAttribute("IdIdioma")).equals(idioma.getCurrentRow().getAttribute("IdIdioma"))){
                    iterador.closeRowSetIterator();
                    return null;
                }   
            }
            iterador.closeRowSetIterator();
            Row row = profe.createRow();
            row.setAttribute("IdIdioma",idioma.getCurrentRow().getAttribute("IdIdioma"));
            row.setAttribute("IdProfesor",(Integer)JSFUtils.resolveExpression("#{bindings.idProfe.inputValue}"));
            profe.insertRow(row);
            
        } else
            System.out.println("Se debe guardar primero el profesor");
        return null;
    }


    public void setPanelGroup3(CorePanelGroup panelGroup3) {
        this.panelGroup3 = panelGroup3;
    }

    public CorePanelGroup getPanelGroup3() {
        return panelGroup3;
    }


    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }

    public void setInputText1(CoreInputText inputText1) {
        this.inputText1 = inputText1;
    }

    public CoreInputText getInputText1() {
        return inputText1;
    }

    public void setInputText3(CoreInputText inputText3) {
        this.inputText3 = inputText3;
    }

    public CoreInputText getInputText3() {
        return inputText3;
    }

    public void setInputText4(CoreInputText inputText4) {
        this.inputText4 = inputText4;
    }

    public CoreInputText getInputText4() {
        return inputText4;
    }

    public void setInputText5(CoreSelectOneChoice inputText5) {
        this.inputText5 = inputText5;
    }

    public CoreSelectOneChoice getInputText5() {
        return inputText5;
    }

    public void setSelectItem1(CoreSelectItem selectItem1) {
        this.selectItem1 = selectItem1;
    }

    public CoreSelectItem getSelectItem1() {
        return selectItem1;
    }

    public void setSelectItem2(CoreSelectItem selectItem2) {
        this.selectItem2 = selectItem2;
    }

    public CoreSelectItem getSelectItem2() {
        return selectItem2;
    }

    public void setInputText6(CoreInputText inputText6) {
        this.inputText6 = inputText6;
    }

    public CoreInputText getInputText6() {
        return inputText6;
    }

    public void setInputText7(CoreInputText inputText7) {
        this.inputText7 = inputText7;
    }

    public CoreInputText getInputText7() {
        return inputText7;
    }

    public void setInputText8(CoreInputText inputText8) {
        this.inputText8 = inputText8;
    }

    public CoreInputText getInputText8() {
        return inputText8;
    }

    public void setSelectInputDate1(CoreSelectInputDate selectInputDate1) {
        this.selectInputDate1 = selectInputDate1;
    }

    public CoreSelectInputDate getSelectInputDate1() {
        return selectInputDate1;
    }


    public void setInputText10(CoreInputText inputText10) {
        this.inputText10 = inputText10;
    }

    public CoreInputText getInputText10() {
        return inputText10;
    }

    public void setInputText12(CoreInputText inputText12) {
        this.inputText12 = inputText12;
    }

    public CoreInputText getInputText12() {
        return inputText12;
    }

    public void setInputText13(CoreInputText inputText13) {
        this.inputText13 = inputText13;
    }

    public CoreInputText getInputText13() {
        return inputText13;
    }

    public void setInputText14(CoreInputText inputText14) {
        this.inputText14 = inputText14;
    }

    public CoreInputText getInputText14() {
        return inputText14;
    }

    public void setInputText15(CoreInputText inputText15) {
        this.inputText15 = inputText15;
    }

    public CoreInputText getInputText15() {
        return inputText15;
    }

    public void setInputText16(CoreSelectOneChoice inputText16) {
        this.inputText16 = inputText16;
    }

    public CoreSelectOneChoice getInputText16() {
        return inputText16;
    }

    public void setSelectItem5(CoreSelectItem selectItem5) {
        this.selectItem5 = selectItem5;
    }

    public CoreSelectItem getSelectItem5() {
        return selectItem5;
    }

    public void setSelectItem3(CoreSelectItem selectItem3) {
        this.selectItem3 = selectItem3;
    }

    public CoreSelectItem getSelectItem3() {
        return selectItem3;
    }

    public void setSelectItem4(CoreSelectItem selectItem4) {
        this.selectItem4 = selectItem4;
    }

    public CoreSelectItem getSelectItem4() {
        return selectItem4;
    }

    public void setSelectItem6(CoreSelectItem selectItem6) {
        this.selectItem6 = selectItem6;
    }

    public CoreSelectItem getSelectItem6() {
        return selectItem6;
    }


    public void setCommandButton5(CoreCommandButton commandButton5) {
        this.commandButton5 = commandButton5;
    }

    public CoreCommandButton getCommandButton5() {
        return commandButton5;
    }

    public void setCommandButton6(CoreCommandButton commandButton6) {
        this.commandButton6 = commandButton6;
    }

    public CoreCommandButton getCommandButton6() {
        return commandButton6;
    }

    public String commandButton5_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}", 0);
        return null;
    }

    public String commandButton6_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Rollback");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}", 0);
        return null;
    }

    public String commandButton2_action() {
         AppModuleImpl service = getAppModule();
         idiomaProfesorViewImpl profe = service.getidiomaProfesorView1();
         if(profe.getCurrentRow()!=null){
            profe.removeCurrentRow();
         }         
        return null;
    }

    public void setPanelHeader1(CorePanelHeader panelHeader1) {
        this.panelHeader1 = panelHeader1;
    }

    public CorePanelHeader getPanelHeader1() {
        return panelHeader1;
    }

    public void setPanelHeader2(CorePanelHeader panelHeader2) {
        this.panelHeader2 = panelHeader2;
    }

    public CorePanelHeader getPanelHeader2() {
        return panelHeader2;
    }

    public void setPanelGroup4(CorePanelGroup panelGroup4) {
        this.panelGroup4 = panelGroup4;
    }

    public CorePanelGroup getPanelGroup4() {
        return panelGroup4;
    }

    public void setCommandButton3(CoreCommandButton commandButton3) {
        this.commandButton3 = commandButton3;
    }

    public CoreCommandButton getCommandButton3() {
        return commandButton3;
    }

    public void setCommandButton2(CoreCommandButton commandButton2) {
        this.commandButton2 = commandButton2;
    }

    public CoreCommandButton getCommandButton2() {
        return commandButton2;
    }

    public void setCommandButton4(CoreCommandButton commandButton4) {
        this.commandButton4 = commandButton4;
    }

    public CoreCommandButton getCommandButton4() {
        return commandButton4;
    }

    public String commandButton4_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        return "GlobalAdminProfesores";
    }


    public void setPanelHorizontal2(CorePanelHorizontal panelHorizontal2) {
        this.panelHorizontal2 = panelHorizontal2;
    }

    public CorePanelHorizontal getPanelHorizontal2() {
        return panelHorizontal2;
    }

    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public void setCommandButton7(CoreCommandButton commandButton7) {
        this.commandButton7 = commandButton7;
    }

    public CoreCommandButton getCommandButton7() {
        return commandButton7;
    }

    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }


    public void setPanelTip1(CorePanelTip panelTip1) {
        this.panelTip1 = panelTip1;
    }

    public CorePanelTip getPanelTip1() {
        return panelTip1;
    }

    public void setOutputText1(CoreOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public CoreOutputText getOutputText1() {
        return outputText1;
    }

    public String commandButton7_action() {
         BindingContainer bindings = getBindings();
         OperationBinding operationBinding = 
             bindings.getOperationBinding("Rollback");
         Object result = operationBinding.execute();
         if (!operationBinding.getErrors().isEmpty()) {
             return null;
         }
        return "GlobalAdminProfesores";
    }

    public void setOutputText503(CoreOutputText outputText503) {
        this.outputText503 = outputText503;
    }

    public CoreOutputText getOutputText503() {
        return outputText503;
    }
}
